//
//  ThirdTableViewCell.m
//  味·道
//
//  Created by 刘孝纯 on 15/6/30.
//  Copyright (c) 2015年 WMR. All rights reserved.
//
#import "DetailViewController.h"
#import "ThirdTableViewCell.h"
#import "MaocHeader.h"
#import "ThirdCollectionViewCell.h"
#import <UIImageView+WebCache.h>
#import "AppDelegate.h"
@implementation ThirdTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _imageview = [[UIImageView alloc] initWithFrame:CGRectMake(5, 20, SCREEN_WIDTH-10, 150)];
        _typeLable = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 50, 10)];
        _typeLable.font = [UIFont systemFontOfSize:10];
        _titleLable = [[UILabel alloc] initWithFrame:CGRectMake(5, 175, SCREEN_WIDTH-10, 10)];
        _titleLable.textAlignment = NSTextAlignmentCenter;
        _titleLable.font = [UIFont systemFontOfSize:10];
        
        
        UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc] init];
        flowlayout.itemSize = CGSizeMake((SCREEN_WIDTH-30)/2, 100);
        flowlayout.minimumInteritemSpacing = 10;
        flowlayout.minimumLineSpacing = 10;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(10, 195, SCREEN_WIDTH-20, 250) collectionViewLayout:flowlayout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor  = [UIColor whiteColor];
        [_collectionView registerClass:[ThirdCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
        
        [self.contentView addSubview:_imageview];
        [self.contentView addSubview:_typeLable];
        [self.contentView addSubview:_titleLable];
        [self.contentView addSubview:_collectionView];
        
        
    }
    return self;
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _arr.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ThirdCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    Recommend2Model *model = _arr[indexPath.item];
    [cell setModel:model];
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    DetailViewController *detailVC  = [[DetailViewController alloc] init];
    Recommend2Model *model = self.arr[indexPath.item];
    detailVC.ID = model.ID;
    AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [delegate.mainNavigationController pushViewController:detailVC animated:YES];
    
}
-(void)setModel:(Recommend3Model *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [_imageview sd_setImageWithURL:[NSURL URLWithString:model.thumb] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    _titleLable.text = model.title;
    [self.collectionView reloadData];
}
@end
